Fix Ballerina Github connector publishing flow code - #135
Fix Ballerina Github connector publishing flow code#135PasinduGunarathne wants to merge 2 commits into
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughOverviewThis PR fixes and updates the Ballerina GitHub connector publishing/sample code in the integration-samples repository. It adds a runnable GitHub trigger sample that demonstrates authenticating with GitHub and creating an issue via the Ballerina GitHub client. ChangesThree files were added or updated under integrator-default-profile/connectors/github_trigger_sample/:
Notes and gaps
WalkthroughThis pull request adds a GitHub trigger sample connector. It declares configurable parameters for githubAuthToken, owner, and repo; initializes an authenticated github:Client using the token; and implements a public main() that posts an issue to /repos/{owner}/{repo}/issues, logging the created issue’s number and URL or returning/logging any error. Sequence Diagram(s)sequenceDiagram
participant Main
participant GitHubClient as github:Client
participant GitHubAPI as GitHub API
participant Logger
Main->>GitHubClient: POST /repos/{owner}/{repo}/issues (create issue)
GitHubClient->>GitHubAPI: HTTP POST issue payload (auth: githubAuthToken)
GitHubAPI-->>GitHubClient: 201 Created (issue number, URL)
GitHubClient->>Logger: log issue number and URL
GitHubClient-->>Main: return success
Note right of GitHubClient: on error -> log error and return error to Main
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
integrator-default-profile/connectors/github_trigger_sample/connections.bal (2)
5-5: ⚡ Quick winRemove redundant string interpolation.
The
githubAuthTokenvariable is already of typestring, so the string interpolation is unnecessary.♻️ Proposed fix
- token: string `${githubAuthToken}` + token: githubAuthToken🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@integrator-default-profile/connectors/github_trigger_sample/connections.bal` at line 5, The token field uses unnecessary string interpolation; replace the expression token: string `${githubAuthToken}` with a direct reference token: githubAuthToken (removing the backtick/template syntax) so the string value from githubAuthToken is used directly and the redundant interpolation is eliminated.
1-7: Use the documentedgithub:ConnectionConfigpattern for client initialization.The library documentation shows explicitly creating a
github:ConnectionConfigbefore initializing the client. Update to:import ballerinax/github; final github:ConnectionConfig config = { auth: { token: string `${githubAuthToken}` } }; final github:Client githubClient = check new (config);This aligns with the ballerinax/github library's recommended initialization pattern.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@integrator-default-profile/connectors/github_trigger_sample/connections.bal` around lines 1 - 7, Replace the direct Client construction with the documented ConnectionConfig pattern: create a github:ConnectionConfig object (e.g., config) that sets auth.token using the existing githubAuthToken value, then pass that config into the github:Client constructor; update references to githubClient to use the new initialization via check new (config) and ensure the import and token interpolation remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@integrator-default-profile/connectors/github_trigger_sample/automation.bal`:
- Around line 9-11: The current call uses resource path syntax to post an issue;
replace it with the library's createIssue remote function: construct a
github:CreateIssueInput record with the title, then call
githubClient->createIssue(inputPayload, owner, repo) and assign the result to
github:Issue githubIssue (handling the check as before). Update the code that
references githubClient, githubIssue, CreateIssueInput, owner and repo
accordingly.
In `@integrator-default-profile/connectors/github_trigger_sample/connections.bal`:
- Around line 3-7: The module-level use of check when creating githubClient
(final github:Client githubClient = check new ...) will cause a panic if
initialization fails; change to safe initialization by removing the module-level
check and either (a) initialize githubClient lazily inside a function (e.g.,
getGithubClient or initGithubClient) that returns an optional or error and uses
trap/if (error) handling, or (b) wrap the new github:Client creation with
trap/var and log or propagate the error instead of panicking, using the
githubAuthToken value for the token; ensure callers handle a nil/optional
githubClient or the returned error accordingly.
---
Nitpick comments:
In `@integrator-default-profile/connectors/github_trigger_sample/connections.bal`:
- Line 5: The token field uses unnecessary string interpolation; replace the
expression token: string `${githubAuthToken}` with a direct reference token:
githubAuthToken (removing the backtick/template syntax) so the string value from
githubAuthToken is used directly and the redundant interpolation is eliminated.
- Around line 1-7: Replace the direct Client construction with the documented
ConnectionConfig pattern: create a github:ConnectionConfig object (e.g., config)
that sets auth.token using the existing githubAuthToken value, then pass that
config into the github:Client constructor; update references to githubClient to
use the new initialization via check new (config) and ensure the import and
token interpolation remain unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f3232e88-cd85-45f8-9a41-c9bf27da9a53
📒 Files selected for processing (3)
integrator-default-profile/connectors/github_trigger_sample/automation.balintegrator-default-profile/connectors/github_trigger_sample/config.balintegrator-default-profile/connectors/github_trigger_sample/connections.bal
Purpose
Goals
Approach
User stories
Release note
Documentation
Training
Certification
Marketing
Automation tests
Security checks
Samples
Related PRs
Migrations (if applicable)
Test environment
Learning